/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package DAO;

import racesuitefx.entities.Starter;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Persistence;
import javax.persistence.Query;

/**
 *
 * @author Wolfgang
 */
public class StarterDAO extends AbstractDAO<Starter> {

      public StarterDAO() {
        super(Starter.class);
    }
    
    public StarterDAO(Class<Starter> entityClass) {
        super(entityClass);
    }

    
    @Override
    protected EntityManager getEntityManager() {
         return Persistence.createEntityManagerFactory("ModelsPU").createEntityManager();
    }
    
    public List<Date> getDetailResult(int raceId, String tagId){
         EntityManager manager = this.getEntityManager();
         String sql = "select time from lap"
                 + " where raceId = ? "
                 + " AND tagId = ? "
                + " group by time asc" ;
        Query q = manager.createNativeQuery(sql);
        q.setParameter(1,raceId);
        q.setParameter(2,tagId);
        List<Date> resultList = new ArrayList<Date>();
        List<Object> result = q.getResultList();
        for (Iterator iterator = result.iterator(); iterator.hasNext();) {
            Object r = (Object) iterator.next();
            resultList.add((Date)r);
        }
        return resultList;
    }
    
}
